<template>
	<view class="box">
		<u-navbar title="绑定手机" height="64" :background="background" title-size="36" title-color="#fff"
			back-icon-color="#fff"></u-navbar>
		<view class="phone">
			<image src="../../static/phone.png" mode=""></image>
			<input type="number" value="" placeholder="请输入新的电话号码" />
		</view>
		<view class="yzmbox">
			<image src="../../static/mail.png" mode=""></image>
			<input type="text" value="" placeholder="请输入短信验证码" />
			<u-toast ref="uToast"></u-toast>
			<u-verification-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange">
			</u-verification-code>
			<u-button @tap="getCode">{{tips}}</u-button>
		</view>
		<view class="ljbd">
			立即绑定
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					// 渐变色
					backgroundImage: 'linear-gradient(176deg,rgb(248,71,52), rgb(249,82,64), rgb(250,101,85))',
				},
				tips: '',
				// refCode: null,
				seconds: 20,
			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				this.$u.toast('倒计时结束');
			},
			start() {
				this.$u.toast('倒计时开始');
			}
		}

	}
</script>

<style lang="scss" scoped>
	.box {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		background-color: #FFFFFF;
	}

	.phone {
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #cccccc;
		width: 690rpx;
		margin: 0 auto;
		padding-bottom: 25rpx;
		box-sizing: border-box;
		margin-top: 142rpx;

		image {
			width: 28rpx;
			height: 40rpx;
		}

		input {
			width: 600rpx;
			margin-left: 40rpx;
		}
	}

	.yzmbox {
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #cccccc;
		width: 690rpx;
		margin: 0 auto;
		padding-bottom: 25rpx;
		box-sizing: border-box;
		margin-top: 34rpx;

		image {
			width: 40rpx;
			height: 30rpx;
		}

		input {
			width: 260rpx;
			margin-left: 40rpx;
			margin-right: 100rpx;
		}
	}

	.ljbd {
		margin: 0 auto;
		width: 584rpx;
		height: 78rpx;
		background-color: #f73f33;
		border-radius: 39rpx;
		line-height: 78rpx;
		text-align: center;
		font-family: SourceHanSansCN-Regular;
		font-size: 36rpx;
		color: #ffffff;
		margin-top: 140rpx;
	}
</style>
